package com.xuequ.answerme.tools;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Shijie on 2015/10/3.
 */
public class Tools {

    public final static int ACTIVITY_SETTINGS = 0;

    private boolean isAvatarChanged = false;
    private boolean isUsernameChanged = false;
    private boolean isSignatureChanged = false;

    public boolean isAvatarChanged() {
        return isAvatarChanged;
    }

    public void setIsAvatarChanged(boolean isAvatarChanged) {
        this.isAvatarChanged = isAvatarChanged;
    }

    public boolean isUsernameChanged() {
        return isUsernameChanged;
    }

    public void setIsUsernameChanged(boolean isUsernameChanged) {
        this.isUsernameChanged = isUsernameChanged;
    }

    public boolean isSignatureChanged() {
        return isSignatureChanged;
    }

    public void setIsSignatureChanged(boolean isSignatureChanged) {
        this.isSignatureChanged = isSignatureChanged;
    }

    public String[] Tags = {"南湖","鉴湖"};

    public static boolean isPhoneNum(String phoneNumber){
        Pattern p = Pattern.compile("^((13[0-9])|(15[^4,//D])|(18[0,5-9]))//d{8}$");
        Matcher m = p.matcher(phoneNumber);
        return m.matches();
    }

    /**
     * 判断网络是否可用
     * @param context
     * @return
     */
    public static boolean isNetAvailable(Context context) {
        ConnectivityManager connectivityManager= (ConnectivityManager)context.
                getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager==null) {
            return false;
        } else {
            NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
            if (info!=null) {
                for (NetworkInfo networkInfo : info) {
                    if (networkInfo.getState()==NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

}
